home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / ARexxDemo.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  8KB  |  248 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/ARexxDemo.c,v 41.11 2000/05/09 20:33:04 mlemos Exp $
  3.  *
  4.  * ARexxDemo.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1994-1995 Jan van den Baard.
  8.  * (C) Copyright 1994-1995 Jaba Development.
  9.  * All Rights Reserved.
  10.  *
  11.  * Description: Simple demonstration of the arexx class.
  12.  *
  13.  * $Log: ARexxDemo.c,v $
  14.  * Revision 41.11  2000/05/09 20:33:04  mlemos
  15.  * Bumped to revision 41.11
  16.  *
  17.  * Revision 1.2  2000/05/09 19:58:27  mlemos
  18.  * Merged with the branch Manuel_Lemos_fixes.
  19.  *
  20.  * Revision 1.1.2.2  1999/02/19 05:03:45  mlemos
  21.  * Added support to build with Storm C.
  22.  *
  23.  * Revision 1.1.2.1  1998/10/12 01:50:43  mlemos
  24.  * Initial revision integrated from Ian sources.
  25.  *
  26.  *
  27.  *
  28.  */
  29.  
  30. /* Execute me to compile with DICE V3.0
  31. dcc arexxdemo.c -proto -mi -ms -lbgui -larexxclass.o
  32. quit
  33. */
  34.  
  35. #include "DemoCode.h"
  36.  
  37. /*
  38. **      Protos for the arexx command functions.
  39. **/
  40. ASM VOID rx_Name( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  41. ASM VOID rx_Version( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  42. ASM VOID rx_Author( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  43. ASM VOID rx_Date( REG(a0) REXXARGS *, REG(a1) struct RexxMsg * );
  44.  
  45. struct Library *BGUIBase = NULL;
  46.  
  47. /*
  48. **      The following commands are
  49. **      valid for this demo.
  50. **/
  51. REXXCOMMAND Commands[] = {
  52.         "NAME",                 NULL,                   rx_Name,
  53.         "VERSION",              NULL,                   rx_Version,
  54.         "AUTHOR",               NULL,                   rx_Author,
  55.         "DATE",                 "SYSTEM/S",             rx_Date,
  56. };
  57.  
  58. /*
  59. **      NAME
  60. **/
  61. #ifdef __STORM__
  62. VOID SAVEDS ASM
  63. #else
  64. SAVEDS ASM VOID
  65. #endif
  66. rx_Name( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  67. {
  68.         /*
  69.         **      Simply return the program name.
  70.         **/
  71.         ra->ra_Result = "ARexxDemo";
  72. }
  73.  
  74. /*
  75. **      VERSION
  76. **/
  77. #ifdef __STORM__
  78. VOID SAVEDS ASM rx_Version( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  79. #else
  80. SAVEDS ASM VOID rx_Version( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  81. #endif
  82. {
  83.         /*
  84.         **      Simply return the program version.
  85.         **/
  86.         ra->ra_Result = "1.0";
  87. }
  88.  
  89. /*
  90. **      AUTHOR
  91. **/
  92. #ifdef __STORM__
  93. VOID SAVEDS ASM rx_Author( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  94. #else
  95. SAVEDS ASM VOID rx_Author( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  96. #endif
  97. {
  98.         /*
  99.         **      Simply return the authors name.
  100.         **/
  101.         ra->ra_Result = "Jan van den Baard";
  102. }
  103.  
  104. /*
  105. **      Buffer for the system date.
  106. **/
  107. UBYTE                   systemDate[ 10 ];
  108.  
  109. /*
  110. **      DATE
  111. **/
  112. #ifdef __STORM__
  113. VOID SAVEDS ASM rx_Date( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  114. #else
  115. SAVEDS ASM VOID rx_Date( REG(a0) REXXARGS *ra, REG(a1) struct RexxMsg *rxm )
  116. #endif
  117. {
  118.         struct DateTime                 dt;
  119.  
  120.         /*
  121.         **      SYSTEM switch specified?
  122.         **/
  123.         if ( ! ra->ra_ArgList[ 0 ] )
  124.                 /*
  125.                 **      No. Simply return the compilation date.
  126.                 **/
  127.                 ra->ra_Result = "25-09-94";
  128.         else {
  129.                 /*
  130.                 **      Compute system date.
  131.                 **/
  132.                 DateStamp(( struct DateStamp * )&dt );
  133.                 dt.dat_Format  = FORMAT_CDN;
  134.                 dt.dat_StrDate = systemDate;
  135.                 dt.dat_Flags   = 0;
  136.                 dt.dat_StrDay  = NULL;
  137.                 dt.dat_StrTime = NULL;
  138.                 DateToStr(&dt);
  139.                 /*
  140.                 **      And return it.
  141.                 **/
  142.                 ra->ra_Result = systemDate;
  143.         }
  144. }
  145.  
  146. /*
  147. **      Object ID's.
  148. **/
  149. #define ID_QUIT                 1
  150.  
  151. VOID StartDemo()
  152. {
  153.    struct Window           *window;
  154.    Object                  *WO_Window, *GO_Quit, *AO_Rexx;
  155.    ULONG                    signal = 0, rxsig = 0L, rc, sigrec;
  156.    BOOL                     running = TRUE;
  157.  
  158.    /*
  159.     *      Create host object.
  160.     */
  161.    if ( AO_Rexx = BGUI_NewObject(BGUI_AREXX_OBJECT, AC_HostName, "RXDEMO", AC_CommandList, Commands, TAG_END )) {
  162.         /*
  163.         **      Create the window object.
  164.         **/
  165.         WO_Window = WindowObject,
  166.                 WINDOW_Title,           "ARexx Demo",
  167.                 WINDOW_SizeGadget,      FALSE,
  168.                 WINDOW_RMBTrap,         TRUE,
  169.                 WINDOW_AutoAspect,      TRUE,
  170.                 WINDOW_MasterGroup,
  171.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  172.                                 StartMember,
  173.                                         InfoFixed( NULL,
  174.                                                    ISEQ_C "This is a small demonstration of\n"
  175.                                                    "the ARexx BOOPSI class. Please run the\n"
  176.                                                    ISEQ_B "Demo.rexx" ISEQ_N " script and see\n"
  177.                                                    "what happens",
  178.                                                    NULL,
  179.                                                    4 ),
  180.                                 EndMember,
  181.                                 StartMember,
  182.                                         HGroupObject,
  183.                                                 VarSpace( 50 ),
  184.                                                 StartMember, GO_Quit  = KeyButton( "_Quit",  ID_QUIT  ), EndMember,
  185.                                                 VarSpace( 50 ),
  186.                                         EndObject,
  187.                                 EndMember,
  188.                         EndObject,
  189.         EndObject;
  190.  
  191.         /*
  192.         **      Object created OK?
  193.         **/
  194.         if ( WO_Window ) {
  195.                 /*
  196.                 **      Assign a key to the button.
  197.                 **/
  198.                 if ( GadgetKey( WO_Window, GO_Quit,  "q" )) {
  199.                         /*
  200.                         **      try to open the window.
  201.                         **/
  202.                         if ( window = WindowOpen( WO_Window )) {
  203.                                 /*
  204.                                 **      Obtain wait masks.
  205.                                 **/
  206.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  207.                                 GetAttr( AC_RexxPortMask, AO_Rexx, &rxsig );
  208.                                 /*
  209.                                 **      Event loop...
  210.                                 **/
  211.                                 do {
  212.                                         sigrec = Wait( signal | rxsig );
  213.  
  214.                                         /*
  215.                                         **      ARexx event?
  216.                                         **/
  217.                                         if ( sigrec & rxsig )
  218.                                                 DoMethod( AO_Rexx, ACM_HANDLE_EVENT );
  219.  
  220.                                         /*
  221.                                         **      Window event?
  222.                                         **/
  223.                                         if ( sigrec & signal ) {
  224.                                                 /*
  225.                                                 **      Handle events.
  226.                                                 **/
  227.                                                 while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  228.                                                         /*
  229.                                                         **      Evaluate return code.
  230.                                                         **/
  231.                                                         switch (rc)
  232.                                                         {
  233.                                                         case WMHI_CLOSEWINDOW:
  234.                                                         case ID_QUIT:
  235.                                                            running = FALSE;
  236.                                                            break;
  237.                                                         }
  238.                                                 }
  239.                                         }
  240.                                 } while ( running );
  241.                         } else PutStr ( "Could not open the window.\n" );
  242.                 } else PutStr( "Could not assign gadget keys.\n" );
  243.                 DisposeObject( WO_Window );
  244.         } else PutStr( "Could not create the window object.\n" );
  245.         DisposeObject( AO_Rexx );
  246.    } else PutStr( "Could not create the ARexx host.\n" );
  247. }
  248.